import javax.swing.JPanel;

import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JMenu;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.Timer;


public class SearchAppointments extends JPanel {
    int location;
    Date date;
    Time time;
    Appointment appointment;
    List<Appointment> app;   
    
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    public SearchAppointments() {
        setLayout(null);
        
        textField = new JTextField();
        textField.setBounds(244, 12, 108, 20);
        add(textField);
        textField.setColumns(10);
        
        final JComboBox comboBox = new JComboBox();
        comboBox.setBounds(169, 46, 183, 20);
        add(comboBox);
        
        JButton btnChooseThisTime = new JButton("Choose this time");
        btnChooseThisTime.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                appointment = (Appointment) comboBox.getSelectedItem();
                appointment.setReason(textField_1.getText());
                location = 20;
            }
        });
        btnChooseThisTime.setBounds(10, 45, 149, 23);
        add(btnChooseThisTime);
        
        
        
        JButton btnCancel = new JButton("Cancel");
        btnCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                location = -1;
            }
        });
        btnCancel.setBounds(10, 79, 89, 23);
        add(btnCancel);
        
        JLabel lblYyyymmdd = new JLabel("yyyy-mm-dd");
        lblYyyymmdd.setBounds(171, 15, 89, 14);
        add(lblYyyymmdd);
        
        JButton btnSearchThisDay = new JButton("Search this day");
        btnSearchThisDay.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                date = Date.valueOf(textField.getText());
                location = -3;
                int j = 0;
                
                for( int i = 0; i < app.size(); i++)
                {
                    if (app.get(i).getDoctor() == textField_2.getText())
                    {
                    comboBox.insertItemAt(app.get(i).getTimeStart(), j);
                    j++;
                    }
                }
            }
        });
        btnSearchThisDay.setBounds(10, 11, 149, 23);
        add(btnSearchThisDay);
        
        textField_1 = new JTextField();
        textField_1.setColumns(10);
        textField_1.setBounds(323, 157, 183, 57);
        add(textField_1);
        
        JLabel lblReason = new JLabel("Reason/Symptoms");
        lblReason.setBounds(375, 121, 108, 14);
        add(lblReason);
        
        textField_2 = new JTextField();
        textField_2.setColumns(10);
        textField_2.setBounds(420, 12, 86, 20);
        add(textField_2);
        
        JLabel lblDoctor = new JLabel("Doctor");
        lblDoctor.setBounds(375, 15, 108, 14);
        add(lblDoctor);
    }
    
    public int getLoc(){
        return location;
    }
    
    public void setLoc(int i){
        location = i;
    }
    
    public Date getDate()
    {
        return date;
    }
    public void setApp(List<Appointment> input){
        app = input;
    }
    public Appointment getAppointment(){
        return appointment;
    }
}
